﻿@model _PLATFORM.DATA.PRODUCT

@{
    ViewBag.Title = "Duplicate Product";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        /*
        * Show / Hide Image Upload Element Name
        */
        $("a.a_changeImage").click(function () {
            $("#div_ImageUpload").toggle(300);
        });

        /* 
        * Show / Hide PDF Upload Element Name
        */
        $("a.a_changePdf").click(function () {
            $("#div_PdfUpload").toggle(300);
        });
    });
</script>

<div id="subNav">
    <ul>
    	<li>@Html.ActionLink("Systems Management", "IndexList", "TruckingSystem")</li>
        @if(ViewBag.ProductType == "Component"){
            <li class="select">@Html.ActionLink("Component Management", "Index", "Component", new { productType = "Component" }, null)</li>
            <li>@Html.ActionLink("Spare Part Management", "Index", "Component", new { productType = "SparePart" }, null)</li>            
        }
        else{
            <li>@Html.ActionLink("Component Management", "Index", "Component", new { productType = "Component" }, null)</li>
            <li class="select">@Html.ActionLink("Spare Part Management", "Index", "Component", new { productType = "SparePart" }, null)</li>
        }
    </ul>
</div>

@if (ViewBag.ProductType == "Component")
{
    <br /><h2>Component Management</h2>
}
else { 
    <br /><h2>Spare Part Management</h2>
}

<div id="subNav2">
    <ul>
        @if (ViewBag.ProductType == "Component")
        {
            <li>@Html.ActionLink("Current Components", "Index", "Component", new { productType = "Component" }, null)</li>
            <li>@Html.ActionLink("Create New Component", "Create", "Component", new { productType = "Component" }, null)<img src="../../Assets/images/add_icon.gif" alt="Add" /></li>
            <li>@Html.ActionLink("Manage Component Selections", "Index", "SelectionOption", new { productType = "Component" }, null)</li>
        }
        else
        {
            <li>@Html.ActionLink("Current Spare Parts", "Index", "Component", new { productType = "Sparepart" }, null)</li>
            <li>@Html.ActionLink("Create New Spare Part", "Create", "Component", new { productType = "Sparepart" }, null)<img src="../../Assets/images/add_icon.gif" alt="Add" /></li>
            <li>@Html.ActionLink("Manage Spare Part Selections", "Index", "SelectionOption", new { productType = "Sparepart" }, null)</li>
        }
    	
        <li  class="select"><a href="#">Duplicate</a></li>
    </ul>
</div>

<div id="lowerContainer">
	<div id="lowerContainerInner">
        @using (Html.BeginForm("Duplicate", "Component", new {c_img = Model.IMAGE, c_pdf = Model.PDF}, FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            @Html.ValidationSummary(true)
            <fieldset>
                <table id="tableMgmt" style="width: 100%;">
                    <tr>
                        @if (ViewBag.ProductType == "Component")
                        {
                            <td class="td160"><b>Component Name</b></td>
                        }
                        else { 
                            <td class="td160"><b>Spare Part Name</b></td>
                        }
                        <td>
                            @Html.EditorFor(model => model.NAME)
                            @Html.ValidationMessageFor(model => model.NAME)
                        </td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.IMAGE)</b></td>
                        <td>
                            @{
                        var imageName = @Html.DisplayFor(model => model.IMAGE);
                        var itemName = @Html.DisplayFor(model => model.NAME);
                        var path = Url.Content("~/Content/User/Images/" + imageName);
                            }
                            @Html.Image(path, @itemName + " image.", new { style = "width:100px;height:75px;", id="CurrentImage" })
                            <a href="#" class="a_changeImage" onclick="return false;">Add / Modify Image?</a>
                            <div id="div_ImageUpload" style="display:none;">
                                <input name="img_imageUpload" type="file" id="imageUpload" value="Upload" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.COST)</b></td>
                        <td>@Html.EditorFor(model => model.COST)
                    @Html.ValidationMessageFor(model => model.COST)</td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.PRICE)</b></td>
                        <td>@Html.EditorFor(model => model.PRICE)
                    @Html.ValidationMessageFor(model => model.PRICE)</td>
                    </tr>
                    <tr>
                        <td><b>@Html.Label("Supplier")</b></td>
                        <td>
                            @{
                            var supplierList = ViewBag.Suppliers;
                            var selectedSupplier = ViewBag.SelectedSupplier;
                            var finalSupplierList = new SelectList(supplierList, "SUPPLIER_ID", "NAME", selectedSupplier);
    
                            @Html.DropDownList("Supplier", finalSupplierList)  
                            }
                        </td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.PART_NUMBER)</b></td>
                        <td>@Html.EditorFor(model => model.PART_NUMBER)
                    @Html.ValidationMessageFor(model => model.PART_NUMBER)</td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.LEAD_TIME)</b></td>
                        <td>@Html.EditorFor(model => model.LEAD_TIME)
                    @Html.ValidationMessageFor(model => model.LEAD_TIME)</td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.INVENTORY)</b></td>
                        <td>@Html.EditorFor(model => model.INVENTORY)
                    @Html.ValidationMessageFor(model => model.INVENTORY)</td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.PDF)</b></td>
                        <td>@{
                        var pdfName = @Html.DisplayFor(model => model.PDF).ToString();
                        var pdfPath = Url.Content("~/Content/User/PDFs/" + pdfName);
                            }
                            @if (!String.IsNullOrEmpty(pdfName))
                            { 
                                <a href="@pdfPath" target="_blank">
                                    @Html.Image(Url.Content("~/Assets/images/pdf_icon.gif"), @itemName + " pdf.", new { style = "width:15px;height:15px;", id = "CurrentPDF" })
                                </a>
                                <a href="#" class="a_changePdf" onclick="return false;">Modify PDF?</a>
                            }
                            else
                            { 
                                <a href="#" class="a_changePdf" onclick="return false;">Add PDF?</a>
                            }
            
                            <div id="div_PdfUpload" style="display:none;">
                                <input name="name_pdfUpload" type="file" id="pdfUpload" value="Upload" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.DESCRIPTION)</b></td>
                        <td>
                            @Html.TextAreaFor(model => model.DESCRIPTION)
                            @Html.ValidationMessageFor(model => model.DESCRIPTION)
                        </td>
                    </tr>
                    <tr>
                        <td><b>@Html.LabelFor(model => model.STATISTICS)</b></td>
                        <td>@Html.TextAreaFor(model => model.STATISTICS)
                    @Html.ValidationMessageFor(model => model.STATISTICS)</td>
                    </tr>
                    @{
                        if (ViewBag.ProductType == "Component") 
                        { 
                            var fittingTypeAssets = ViewBag.FittingTypeAssetList as IEnumerable<_PLATFORM.DATA.FITTING_TYPE_ASSET>;
                            var productFittingTypeAssets = ViewBag.ProductFittingTypeAssets as IEnumerable<_PLATFORM.DATA.PRODUCT_FITTING_TYPE_ASSET>;
                
                            foreach (var fittingType in ViewBag.FittingTypes as List<_PLATFORM.DATA.FITTING_TYPE>)
                            {
                                <tr>
                                    <td>
                                        <b>
                                            @Html.Label(fittingType.NAME)
                                        </b>
                                    </td>
                                    <td>
                                        @{
                                           var mainList = fittingTypeAssets.Where(f => f.FITTING_TYPE_ID == fittingType.FITTING_TYPE_ID).OrderBy(t => t.NAME);
                                           var subList = productFittingTypeAssets.Where(p => p.PRODUCT_ID == ViewBag.ProductID).Where(p => p.FITTING_TYPE_ASSET.FITTING_TYPE_ID == fittingType.FITTING_TYPE_ID).Select(s => s.FITTING_TYPE_ASSET.FITTING_TYPE_ASSET_ID).ToList();
                                           var finalList = subList.Count > 0 ? new MultiSelectList(mainList, "FITTING_TYPE_ASSET_ID", "NAME", subList) : new MultiSelectList(mainList, "FITTING_TYPE_ASSET_ID", "NAME");
                                           var categoryName = fittingType.NAME;      
                                        }
                                        @Html.ListBox(categoryName, finalList)      
                                    </td>
                                </tr>
                            }
                        }
                    }
                    <tr>
			            <td></td>
			            <td>
                            <input type="submit" value="Save" class="button default btnLarge" />
                        
                            @if (ViewBag.ProductType == "Component")
                            {
                            
                                <a href="../../Component?productType=Component" class="button cancel btnLarge">Cancel</a>
                            }
                            else
                            { 
                                <a href="../../Component?productType=SparePart" class="button cancel btnLarge">Cancel</a>
                            }
                        </td>
		            </tr>
                </table>
            </fieldset>
        }
    </div>
</div>

